import { ref } from 'vue'
import { useRequest } from 'vue-request'

import { textLabelApi } from '@/services/index'
import { checkPermissions } from '@/utils/share'

export const useProgress = (taskId: string) => {
  // 获取标注进度
  const progressInfo = ref()
  const getLabelProgress = async () => {
    const { data } = await textLabelApi.getMarkTaskProgress({}, { urlParams: { id: taskId } })
    progressInfo.value = data
  }

  return {
    progressInfo,
    getLabelProgress
  }
}

export const useTask = (taskId: string) => {
  const isEditable = ref(true)
  const detailInfo = ref()

  // 获取任务详情
  const { loading, runAsync: runGetTaskDetail } = useRequest<any>(textLabelApi.getTaskDetail)
  const getTaskDetail = async () => {
    const { data } = await runGetTaskDetail({}, { urlParams: { id: taskId } })
    isEditable.value = checkPermissions(data?.createType, data?.readOnly)
    detailInfo.value = data
  }

  return {
    loading,
    isEditable,
    detailInfo,
    getTaskDetail
  }
}
